package com.ruoyi.redtea.dualprevent.controller;


import com.ruoyi.common.core.domain.R;
import com.ruoyi.redtea.dualprevent.domain.bo.TrainRiskPointControlWaysBo;
import com.ruoyi.redtea.dualprevent.domain.entity.TrainRiskPointControlWays;
import com.ruoyi.redtea.dualprevent.service.TrainRiskPointControlWaysService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 风险点管控措施(TrainRiskPointControlWays)表控制层
 *
 * @author makejava
 * @since 2024-05-15 14:38:26
 */
@RestController
@RequestMapping("trainRiskPointControlWays")
public class TrainRiskPointControlWaysController {
    /**
     * 服务对象
     */
    @Resource
    private TrainRiskPointControlWaysService trainRiskPointControlWaysService;

    @GetMapping("/controlWays/list")
    public R<?> selectList() {
        return R.ok(trainRiskPointControlWaysService.queryList());
    }

    /**
     * 查询排查项
     * @return
     */
    @GetMapping("/controlWays/avatarList")
    public R<?> selectWaysItemList() {
        return R.ok(trainRiskPointControlWaysService.queryAvatarList());
    }

    /**
     * 新增措施
     *
     * @param controlWaysBo 实体对象
     * @return 新增结果
     */
    @PostMapping("addControlWay")
    public R<?> insertControlWay(@RequestBody TrainRiskPointControlWaysBo controlWaysBo) {
        return R.ok(this.trainRiskPointControlWaysService.insertRiskPointControlWaysAndItem(controlWaysBo));
    }

    /**
     * 修改数据
     *
     * @param controlWaysBo 实体对象
     * @return 修改结果
     */
    @PutMapping("updateControlWay")
    public R<?> updateControlWay(@RequestBody TrainRiskPointControlWaysBo controlWaysBo) {
        return R.ok(this.trainRiskPointControlWaysService.updateRiskPointControlWaysAndItem(controlWaysBo));
    }

    /**
     * 删除排查项数据
     *
     * @param id 主键结合
     * @return 删除结果
     */
    @DeleteMapping("/wayItem")
    public R<?> delete(@RequestParam("id") Long id) {
        return R.ok(this.trainRiskPointControlWaysService.delControlWayItem(Math.toIntExact(id)));
    }
}

